package com.mall.mymall.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.mymall.dao.dto.QueryDto;
import com.mall.mymall.dao.dto.StoresDto;
import com.mall.mymall.dao.dto.querypage.StorePageRequest;
import com.mall.mymall.dao.entity.Stores;
import com.mall.mymall.mapper.StoresMapper;
import com.mall.mymall.service.StoresService;
import org.springframework.stereotype.Service;

@Service
public class StoresServiceImpl extends ServiceImpl<StoresMapper, Stores> implements StoresService {
    @Override
    public QueryDto<StoresDto> pageStores(StorePageRequest storePageRequest) {
        // 创建分页对象
        Page<StoresDto> page = new Page<>(storePageRequest.getPageRequestDto().getPage(), storePageRequest.getPageRequestDto().getSize());

        // 执行自定义分页查询
        IPage<StoresDto> resultPage = this.baseMapper.selectStoresPage(page, storePageRequest.getQuery());

        // 构造返回结果
        QueryDto<StoresDto> result = new QueryDto<>();
        result.setTotal((int) resultPage.getTotal());
        result.setRecords(resultPage.getRecords());

        return result;
    }
}
